package com.itbaizhan.service;

import com.itbaizhan.dao.AccountDao;
import com.itbaizhan.domain.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountService {

    @Autowired
    private AccountDao accountDao;

    @Transactional
    public void transfer(int id1, int id2, double money){
        Account account1 = accountDao.findById(id1);
        account1.setBalance(account1.getBalance()-money);
        accountDao.update(account1);
        int i = 1 / 0;
        Account account2 = accountDao.findById(2);
        account2.setBalance(account2.getBalance()+money);
        accountDao.update(account2);
    }
}
